<!DOCTYPE html>





<html class="theme-next gemini" lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="generator" content="Hexo 3.9.0">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.3.0">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/CNY32x32.png?v=7.3.0">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/CNY16x16.png?v=7.3.0">
  <link rel="mask-icon" href="/images/logo.svg?v=7.3.0" color="#222">

<link rel="stylesheet" href="/css/main.css?v=7.3.0">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '7.3.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":true},
    save_scroll: false,
    copycode: {"enable":true,"show_result":true,"style":null},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.xml',
    motion: {"enable":false,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    translation: {
      copy_button: '复制',
      copy_success: '复制成功',
      copy_failure: '复制失败'
    }
  };
</script>

  <meta name="description" content="前言：远程仓库地址：https://github.com/XiaoZhong233/GIS_ALG 光栏法是一种矢量数据的压缩算法。光栏法的基本思路是对每一条曲线上的所有点, 逐点定义一个扇形区域。若曲线的下一节点在扇形外, 则保留当前节点; 若曲线的下一节点在扇形内, 则舍去当前节点。">
<meta name="keywords" content="GIS算法">
<meta property="og:type" content="article">
<meta property="og:title" content="GIS算法基础（十）矢量压缩算法-光栏法">
<meta property="og:url" content="localhost:4000/2019/06/01/GIS算法基础（十）矢量压缩算法-光栏法/index.html">
<meta property="og:site_name" content="钟浩伟的个人博客">
<meta property="og:description" content="前言：远程仓库地址：https://github.com/XiaoZhong233/GIS_ALG 光栏法是一种矢量数据的压缩算法。光栏法的基本思路是对每一条曲线上的所有点, 逐点定义一个扇形区域。若曲线的下一节点在扇形外, 则保留当前节点; 若曲线的下一节点在扇形内, 则舍去当前节点。">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210103.png!blog">
<meta property="og:image" content="">
<meta property="og:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210127.png!blog">
<meta property="og:image" content="">
<meta property="og:image" content="">
<meta property="og:image" content="">
<meta property="og:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210153.png!blog">
<meta property="og:image" content="">
<meta property="og:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210203.png!blog">
<meta property="og:image" content="">
<meta property="og:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210214.png!blog">
<meta property="og:image" content="">
<meta property="og:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210226.png!blog">
<meta property="og:image" content="">
<meta property="og:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210235.png!blog">
<meta property="og:image" content="">
<meta property="og:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210244.png!blog">
<meta property="og:image" content="">
<meta property="og:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210253.png!blog">
<meta property="og:image" content="">
<meta property="og:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210302.png!blog">
<meta property="og:image" content="">
<meta property="og:updated_time" content="2019-09-07T13:03:07.178Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="GIS算法基础（十）矢量压缩算法-光栏法">
<meta name="twitter:description" content="前言：远程仓库地址：https://github.com/XiaoZhong233/GIS_ALG 光栏法是一种矢量数据的压缩算法。光栏法的基本思路是对每一条曲线上的所有点, 逐点定义一个扇形区域。若曲线的下一节点在扇形外, 则保留当前节点; 若曲线的下一节点在扇形内, 则舍去当前节点。">
<meta name="twitter:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210103.png!blog">
  <link rel="canonical" href="localhost:4000/2019/06/01/GIS算法基础（十）矢量压缩算法-光栏法/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true,
    isPage: false,
    isArchive: false
  };
</script>

  <title>GIS算法基础（十）矢量压缩算法-光栏法 | 钟浩伟的个人博客</title>
  








  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  <div class="container sidebar-position-left">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">钟浩伟的个人博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">欢迎光临</p>
      
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
      
      
      
        
        <li class="menu-item menu-item-home">
      
    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-tags">
      
    

    <a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-categories">
      
    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-archives">
      
    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a href="javascript:;" class="popup-trigger">
        
          <i class="menu-item-icon fa fa-search fa-fw"></i> <br>搜索</a>
      </li>
    
  </ul>

</nav>
  <div class="site-search">
    
  <div class="popup search-popup">
  <div class="search-header">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <div class="search-input-wrapper">
      <input autocomplete="off" autocorrect="off" autocapitalize="none"
             placeholder="搜索..." spellcheck="false"
             type="text" id="search-input">
    </div>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
  </div>
  <div id="search-result"></div>
</div>


  </div>
</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
            

          <div id="content" class="content page-post-detail">
            

  <div id="posts" class="posts-expand">
    

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="localhost:4000/2019/06/01/GIS算法基础（十）矢量压缩算法-光栏法/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="钟浩伟">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/profile.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="钟浩伟的个人博客">
    </span>
      <header class="post-header">

        
          <h1 class="post-title" itemprop="name headline">GIS算法基础（十）矢量压缩算法-光栏法

            
          </h1>
        

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2019-06-01 14:05:07" itemprop="dateCreated datePublished" datetime="2019-06-01T14:05:07+08:00">2019-06-01</time>
            </span>
          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/GIS/" itemprop="url" rel="index"><span itemprop="name">GIS</span></a></span>

                
                
              
            </span>
          

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="前言："><a href="#前言：" class="headerlink" title="前言："></a>前言：</h1><p><strong>远程仓库地址：<a href="https://github.com/XiaoZhong233/GIS_ALG" target="_blank" rel="noopener">https://github.com/XiaoZhong233/GIS_ALG</a></strong></p>
<p>光栏法是一种矢量数据的压缩算法。光栏法的基本思路是对每一条曲线上的所有点, 逐点定义一个扇形区域。若曲线的下一节点在扇形外, 则保留当前节点; 若曲线的下一节点在扇形内, 则舍去当前节点。</p>
<a id="more"></a>

<hr>
<h1 id="说明："><a href="#说明：" class="headerlink" title="说明："></a>说明：</h1><p>光栏法与道格拉斯算法都是矢量压缩算法，但是光栏法能很好的保存线的形状，而道格拉斯普克算法是概化算法，他的作用主要是把凹凸不平的折线变得平直，因此算“概化”算法</p>
<h1 id="算法步骤："><a href="#算法步骤：" class="headerlink" title="算法步骤："></a>算法步骤：</h1><p><img src="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210103.png!blog" alt="20190907210103"><img src="" alt="点击并拖拽以移动"></p>
<p><strong>1、输入光栏的口径d</strong></p>
<p>这个口径也就是每次扫描的扇形区域，若曲线的下一节点在扇形外, 则保留当前节点; 若曲线的下一节点在扇形内, 则舍去当前节点。</p>
<p><strong>2、读取坐标</strong></p>
<p>1、2两点坐标，记入p1，p2</p>
<p><strong>3、建立光栏</strong></p>
<p>连接p1和p2点，过 p2点作一条垂直于p1p2 的直线，在该垂线上取 两点a1和a2，使a1p2＝ a2p2＝d／2，此时a1和 a2为“光栏”边界点， p1与a1、p1与a2的连线 为以p1为顶点的扇形的 两条边，这就定义了一 个扇形(这个扇形的口朝 向曲线的前进方向，边 长是任意的)。通过p1并在扇形内的所有直线都具有这种性质， 即p1p2上各点到这些直线的垂距都不大于d/2。</p>
<p>若p3点在扇形内，则舍去p2点。然后连接p1和p3，过p3作 p1p1的垂线，该垂线与前面定义的扇形边交于c1和c2。在垂线 上找到b1和b2点，使p3b1＝p3b2＝d／2，若b1或b2点落在原扇 形外面，则用c1或c2取代。此时用p1b1和p1c2定义一个新的扇 形，这当然是口径(b1c2)缩小了的“光栏”。</p>
<p><strong>4、检查下一节点</strong></p>
<p>若该点在新扇形内，则重复第(2)步；直 到发现有一个节点在最新定义的扇形外为止。</p>
<p>当发现在扇形外的节点，如p4，此时保留p3点，以p3作为 新起点，重复1°～3°。如此继续下去，直到整个点列检测完 为止。所有被保留的节点(含首、末点)，顺序地构成了简化后 的新点列。</p>
<p><img src="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210127.png!blog" alt="20190907210127"><img src="" alt="点击并拖拽以移动"></p>
<h1 id="实现代码："><a href="#实现代码：" class="headerlink" title="实现代码："></a><strong>实现代码：</strong></h1><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br></pre></td><td class="code"><pre><span class="line">	<span class="comment">/**</span></span><br><span class="line"><span class="comment">	 * 光栏法压缩折线</span></span><br><span class="line"><span class="comment">	 * <span class="doctag">@param</span> caliber 口径</span></span><br><span class="line"><span class="comment">	 * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> Polyline <span class="title">simplify_LightBar</span><span class="params">(<span class="keyword">double</span> caliber)</span> </span>&#123;</span><br><span class="line">		<span class="keyword">if</span>(caliber&lt;=<span class="number">0</span>)</span><br><span class="line">			<span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">		<span class="keyword">if</span>(<span class="keyword">this</span>.points.size()&lt;<span class="number">2</span>) &#123;</span><br><span class="line">			<span class="keyword">return</span> <span class="keyword">this</span>;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="comment">//求光栏下边界</span></span><br><span class="line">		List&lt;Point&gt; points = <span class="keyword">this</span>.getPoints();</span><br><span class="line">		Point p1 = points.get(<span class="number">0</span>);</span><br><span class="line">		Point p2 = points.get(<span class="number">1</span>);</span><br><span class="line">		Line line = <span class="keyword">new</span> Line(p1,p2);</span><br><span class="line">		<span class="keyword">double</span> len = line.getLength();</span><br><span class="line">		<span class="keyword">double</span> angle1 = Math.toDegrees(Math.atan2(.<span class="number">5</span>*caliber,len));</span><br><span class="line">		<span class="keyword">double</span> angle2 = line.getVector2D().getAngle();</span><br><span class="line">		</span><br><span class="line">		<span class="comment">//求光栏下边界</span></span><br><span class="line">		Line down = <span class="keyword">new</span> Line(angle2-angle1, p1);</span><br><span class="line">		<span class="comment">//求光栏上边界</span></span><br><span class="line">		Line up = <span class="keyword">new</span> Line(angle1+angle2,p1);</span><br><span class="line">		</span><br><span class="line"></span><br><span class="line"><span class="comment">//		//计算光栏a1,a2坐标</span></span><br><span class="line"><span class="comment">//		//p1p2直线的法线矢量</span></span><br><span class="line"><span class="comment">//		Vector2D n = line.getN();</span></span><br><span class="line"><span class="comment">//		//光栏垂直平分线的垂线</span></span><br><span class="line"><span class="comment">//		Line l = new Line(n,p2);</span></span><br><span class="line"><span class="comment">//		Point a1 = l.intercourse(down);</span></span><br><span class="line"><span class="comment">//		Point a2 = l.intercourse(up);</span></span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">2</span>;i&lt;points.size();i++) &#123;</span><br><span class="line">			Point p = points.get(i);</span><br><span class="line">			<span class="comment">//如果下一个点在光栏内，则删除上一个点，当前点为新p2</span></span><br><span class="line">			<span class="comment">//如果不在，则保留上一个点，以上一个点为新p1</span></span><br><span class="line">			<span class="keyword">if</span>(isInLightBar(up, down, p)) &#123;</span><br><span class="line">				points.get(i-<span class="number">1</span>).setEnable(<span class="keyword">false</span>);</span><br><span class="line">				p2=p;</span><br><span class="line">				<span class="comment">//求当前点与p1的垂线</span></span><br><span class="line">				Line line2 = <span class="keyword">new</span> Line(p1,p2);</span><br><span class="line">				Vector2D nn = line.getN();</span><br><span class="line">				Line line3 = <span class="keyword">new</span> Line(nn,p);</span><br><span class="line">				<span class="comment">//建立新的光栏</span></span><br><span class="line">				<span class="keyword">double</span> length =  line2.getLength();</span><br><span class="line">				<span class="keyword">double</span> angle11 = Math.toDegrees(Math.atan(.<span class="number">5</span>*caliber/length));</span><br><span class="line">				<span class="keyword">double</span> angle22 = line2.getVector2D().getAngle();</span><br><span class="line">				Line newDown = <span class="keyword">new</span> Line(angle22-angle11, p1);</span><br><span class="line">				Line newUp = <span class="keyword">new</span> Line(angle11+angle22,p1);</span><br><span class="line">				<span class="comment">//求当前点与p1的连线的垂线与新光栏的交点</span></span><br><span class="line">				Point b1 = line3.intercourse(newDown);</span><br><span class="line">				Point b2 = line3.intercourse(newUp);</span><br><span class="line">				<span class="comment">//检查新光栏的交点是否在原光栏内</span></span><br><span class="line">				<span class="comment">//如果在就使用新光栏，不在就构建另一个光栏</span></span><br><span class="line">				<span class="keyword">if</span>(isInLightBar(up, down, b1) &amp;&amp; isInLightBar(up, down, b2)) &#123;</span><br><span class="line">					down = newDown;</span><br><span class="line">					up = newUp;</span><br><span class="line">				&#125;<span class="keyword">else</span> &#123;</span><br><span class="line">					<span class="comment">//只有b1在光栏内</span></span><br><span class="line">					<span class="keyword">if</span>(isInLightBar(up, down, b1)) &#123;</span><br><span class="line">						down = <span class="keyword">new</span> Line(p1,b1);</span><br><span class="line">					&#125;</span><br><span class="line">					<span class="keyword">if</span>(isInLightBar(up, down, b2)) &#123;</span><br><span class="line">						up = <span class="keyword">new</span> Line(p1,b2);</span><br><span class="line">					&#125;</span><br><span class="line">				&#125;</span><br><span class="line">				</span><br><span class="line">			&#125;<span class="keyword">else</span> &#123;</span><br><span class="line">				points.get(i-<span class="number">1</span>).setEnable(<span class="keyword">true</span>);</span><br><span class="line">				p1=points.get(i-<span class="number">1</span>);</span><br><span class="line">				p2=points.get(i);</span><br><span class="line">				line = <span class="keyword">new</span> Line(p1,p2);</span><br><span class="line">				len = line.getLength();</span><br><span class="line">				angle1 = Math.toDegrees(Math.atan(.<span class="number">5</span>*caliber/len));</span><br><span class="line">				angle2 = line.getVector2D().getAngle();</span><br><span class="line">				<span class="comment">//求光栏上下边界</span></span><br><span class="line">				down = <span class="keyword">new</span> Line(angle2-angle1, p1);</span><br><span class="line">				up = <span class="keyword">new</span> Line(angle1+angle2,p1);</span><br><span class="line">			&#125;</span><br><span class="line">			</span><br><span class="line">			</span><br><span class="line">			</span><br><span class="line">		&#125;</span><br><span class="line">		</span><br><span class="line">		List&lt;Point&gt; selectedPoints = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">		Collections.addAll(selectedPoints,  <span class="keyword">new</span>  Point[<span class="keyword">this</span>.points.size()]); </span><br><span class="line">		Collections.copy(selectedPoints, <span class="keyword">this</span>.points);</span><br><span class="line">		Iterator&lt;Point&gt; iterator = selectedPoints.iterator();</span><br><span class="line">		<span class="keyword">while</span> (iterator.hasNext()) &#123;</span><br><span class="line">			Point point = (Point) iterator.next();</span><br><span class="line">			<span class="keyword">if</span>(!point.isEnable()) &#123;</span><br><span class="line">				iterator.remove();</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		</span><br><span class="line">		<span class="keyword">return</span> <span class="keyword">new</span> Polyline(selectedPoints);</span><br><span class="line">	&#125;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 判断点是否光栏内</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> up</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> down</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> point</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">boolean</span> <span class="title">isInLightBar</span><span class="params">(Line up,Line down,Point point)</span> </span>&#123;</span><br><span class="line">	Point start = up.getStart();</span><br><span class="line">	Line line = <span class="keyword">new</span> Line(start,point);</span><br><span class="line">	Vector2D upVector = up.getVector2D();</span><br><span class="line">	Vector2D downVector = down.getVector2D();</span><br><span class="line">	Vector2D target = line.getVector2D();</span><br><span class="line">	<span class="comment">//利用矢量的叉积判断即可</span></span><br><span class="line">	<span class="keyword">if</span>(target.crossProduct(upVector)&gt;=<span class="number">0</span> &amp;&amp; target.crossProduct(downVector) &lt;=<span class="number">0</span>) &#123;</span><br><span class="line">		<span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<h1 id="运行结果："><a href="#运行结果：" class="headerlink" title="运行结果："></a>运行结果：</h1><p>原始数据：</p>
<p><img src="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210153.png!blog" alt="20190907210153"><img src="" alt="点击并拖拽以移动"></p>
<p>光栏法压缩后（阈值5）</p>
<p><img src="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210203.png!blog" alt="20190907210203"><img src="" alt="点击并拖拽以移动"></p>
<p><img src="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210214.png!blog" alt="20190907210214"><img src="" alt="点击并拖拽以移动"></p>
<p>因为有两条折线，所以概化了两次</p>
<p>再次使用光栏法压缩（阈值调为10）</p>
<p><img src="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210226.png!blog" alt="20190907210226"><img src="" alt="点击并拖拽以移动"></p>
<p><img src="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210235.png!blog" alt="20190907210235"><img src="" alt="点击并拖拽以移动"></p>
<p>再次使用光栏法压缩（阈值调为20）</p>
<p><img src="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210244.png!blog" alt="20190907210244"><img src="" alt="点击并拖拽以移动"></p>
<p><img src="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210253.png!blog" alt="20190907210253"><img src="" alt="点击并拖拽以移动"></p>
<p>再次使用光栏法压缩（阈值调为50）</p>
<p><img src="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/20190907210302.png!blog" alt="20190907210302"><img src="" alt="点击并拖拽以移动"></p>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a><strong>总结</strong></h1><p>与道格拉斯算法的对比：</p>
<p>道格拉斯普克算法采用递归实现，它需要对整条曲线进行扫描，才能进行压缩，而且采用递归，计算量较大。</p>
<p>光栏法能给定阈值保留曲线特征点、并且他和道克拉斯普克算法最大的不同是，他能实时计算的，且计算量较小，占用的内存也小了。</p>
<p>因此光栏法是一种优秀高效的矢量压缩算法</p>

    </div>

    
    
    
      
  <div class="popular-posts-header">相关文章推荐</div>
  <ul class="popular-posts">
    <li class="popular-posts-item">
      
      
      <div class="popular-posts-title"><a href="\2018\12\08\GIS算法基础（七）矢量数据向栅格数据的转换（面转换的边界代数算法实现）\" rel="bookmark">GIS算法基础（七）矢量数据向栅格数据的转换（面转换的边界代数算法实现）</a></div>
      
    </li>
  
    <li class="popular-posts-item">
      
      
      <div class="popular-posts-title"><a href="\2019\06\01\GIS算法基础（九）矢量压缩算法-道格拉斯普克算法\" rel="bookmark">GIS算法基础（九）矢量压缩算法-道格拉斯普克算法</a></div>
      
    </li>
  
    <li class="popular-posts-item">
      
      
      <div class="popular-posts-title"><a href="\2018\11\30\GIS算法基础（三）计算几何基础（下）\" rel="bookmark">GIS算法基础（三）计算几何基础（下）</a></div>
      
    </li>
  
    <li class="popular-posts-item">
      
      
      <div class="popular-posts-title"><a href="\2018\10\08\GIS算法基础（一）-计算几何基础（上）\" rel="bookmark">GIS算法基础（一） 计算几何基础（上）</a></div>
      
    </li>
  
    <li class="popular-posts-item">
      
      
      <div class="popular-posts-title"><a href="\2018\12\08\GIS算法基础（六）矢量数据向栅格数据的转换（面转换的射线算法实现）\" rel="bookmark">GIS算法基础（六）矢量数据向栅格数据的转换（面转换的射线算法实现）</a></div>
      
    </li>
  
  </ul>


    
    <div>
      
      <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束感谢您的阅读,如有疑问，请联系<a href="mailto:610596547@qq.com">610596547@qq.com</a>-------------</div>
    
</div>
      
    </div>
        
      

      <footer class="post-footer">
          
            
          
          <div class="post-tags">
            
              <a href="/tags/GIS算法/" rel="tag"># GIS算法</a>
            
          </div>
        

        

          <div class="post-nav">
            <div class="post-nav-next post-nav-item">
              
                <a href="/2019/06/01/GIS算法基础（九）矢量压缩算法-道格拉斯普克算法/" rel="next" title="GIS算法基础（九）矢量压缩算法-道格拉斯普克算法">
                  <i class="fa fa-chevron-left"></i> GIS算法基础（九）矢量压缩算法-道格拉斯普克算法
                </a>
              
            </div>

            <span class="post-nav-divider"></span>

            <div class="post-nav-prev post-nav-item">
              
                <a href="/2019/07/07/加法器的实现及优化/" rel="prev" title="加法器的实现及优化">
                  加法器的实现及优化 <i class="fa fa-chevron-right"></i>
                </a>
              
            </div>
          </div>
        
      </footer>
    
  </div>
  
  
  
  </article>

  </div>


          </div>
          

        </div>
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">

          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image"
      src="/images/profile.jpg"
      alt="钟浩伟">
  <p class="site-author-name" itemprop="name">钟浩伟</p>
  <div class="site-description motion-element" itemprop="description"></div>
</div>
  <nav class="site-state motion-element">
      <div class="site-state-item site-state-posts">
        
          <a href="/archives/">
        
          <span class="site-state-item-count">44</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
    
      
      
      <div class="site-state-item site-state-categories">
        
          
            <a href="/categories/">
          
        
        
        
          
        
          
        
          
        
          
        
          
        
          
        
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">分类</span>
        </a>
      </div>
    
      
      
      <div class="site-state-item site-state-tags">
        
          
            <a href="/tags/">
          
        
        
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
        <span class="site-state-item-count">15</span>
        <span class="site-state-item-name">标签</span>
        </a>
      </div>
    
  </nav>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="https://github.com/XiaoZhong233" title="GitHub &rarr; https://github.com/XiaoZhong233" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
    
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="mailto:601596547@qq.com" title="E-Mail &rarr; mailto:601596547@qq.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
    
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="https://blog.csdn.net/weixin_41154636" title="CSDN &rarr; https://blog.csdn.net/weixin_41154636" rel="noopener" target="_blank"><i class="fa fa-fw fa-book"></i>CSDN</a>
      </span>
    
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="http://profile.zhonghaowei.xyz/" title="Profile &rarr; http://profile.zhonghaowei.xyz/" rel="noopener" target="_blank"><i class="fa fa-fw fa-address-card-o"></i>Profile</a>
      </span>
    
  </div>



        </div>
      </div>
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#前言："><span class="nav-number">1.</span> <span class="nav-text">前言：</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#说明："><span class="nav-number">2.</span> <span class="nav-text">说明：</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#算法步骤："><span class="nav-number">3.</span> <span class="nav-text">算法步骤：</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#实现代码："><span class="nav-number">4.</span> <span class="nav-text">实现代码：</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#运行结果："><span class="nav-number">5.</span> <span class="nav-text">运行结果：</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#总结"><span class="nav-number">6.</span> <span class="nav-text">总结</span></a></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      



    </div>
  </aside>
  <div id="sidebar-dimmer"></div>




      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love" id="animate">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">钟浩伟</span>
</div>


<div id="days"></div>
<div class="BbeiAn-info">
   	粤ICP备 -
    <a target="_blank" href="http://beian.miit.gov.cn" style="color:#f0d784"  rel="nofollow">粤ICP备19111001号-1</a> <!--a标签中增加nofollow属性，避免爬虫出站。-->| 
	<a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=" style="color:#f0d784;text-decoration:none;padding-left:30px;background:url(https://s1.ax1x.com/2018/09/29/ilmwIH.png) no-repeat left center" rel="nofollow">粤公网安备 粤ICP备19111001号-1</a>	  <!--这里将图标作为了背景，以使得能和后面的文字在同一行-->
</div>

<script>
function show_date_time(){
    window.setTimeout("show_date_time()", 1000);
    BirthDay=new Date("08/15/2019 22:40:14");
    today=new Date();
    timeold=(today.getTime()-BirthDay.getTime());
    sectimeold=timeold/1000
    secondsold=Math.floor(sectimeold);
    msPerDay=24*60*60*1000
    e_daysold=timeold/msPerDay
    daysold=Math.floor(e_daysold);
    e_hrsold=(e_daysold-daysold)*24;
    hrsold=setzero(Math.floor(e_hrsold));
    e_minsold=(e_hrsold-hrsold)*60;
    minsold=setzero(Math.floor((e_hrsold-hrsold)*60));
    seconds=setzero(Math.floor((e_minsold-minsold)*60));
    document.getElementById('days').innerHTML="<p>小破站已运行 "+daysold+" 天 "+hrsold+" 小时 "+minsold+" 分 "+seconds+" 秒</p>";
}
function setzero(i) {
    if (i<10) {
        i="0" + i
    };
    return i;
}
show_date_time();
</script>

        








        
      </div>
    </footer>
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>

    

  </div>

  
  <script src="/lib/jquery/index.js?v=3.4.1"></script>

<script src="/js/utils.js?v=7.3.0"></script>

<script src="/js/schemes/pisces.js?v=7.3.0"></script>



<script src="/js/next-boot.js?v=7.3.0"></script>




  















  <script src="/js/local-search.js?v=7.3.0"></script>










<script>
if (document.querySelectorAll('pre.mermaid').length) {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js', () => {
    mermaid.initialize({
      theme: 'default',
      logLevel: 3,
      flowchart: { curve: 'linear' },
      gantt: { axisFormat: '%m/%d/%Y' },
      sequence: { actorMargin: 50 }
    });
  }, window.mermaid);
}
</script>




  

  

  


  
  <script src="/js/scrollspy.js?v=7.3.0"></script>
<script src="/js/post-details.js?v=7.3.0"></script>



  
  <script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>
  
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"log":false,"model":{"jsonPath":"/live2dw/assets/assets/hijiki.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":false}});</script></body>
</html>
